package marchsoft.modules.four.admin.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import marchsoft.base.BasicServiceImpl;
import marchsoft.base.PageVO;
import marchsoft.modules.four.admin.entity.dto.StudyDataDTO;
import marchsoft.modules.four.admin.mapper.SafeTypeMapper;
import marchsoft.modules.four.admin.service.StudyDataService;
import marchsoft.modules.four.common.entity.SafeType;
import marchsoft.modules.four.common.entity.StudyData;
import marchsoft.modules.four.common.mapper.MapperStudyData;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
@RequiredArgsConstructor
public class StudyDataServiceImpl extends BasicServiceImpl<MapperStudyData, StudyData> implements StudyDataService {

    private final SafeTypeMapper safeTypeMapper;


    @Override // 分页条件查询学习资料
    public IPage<StudyData> queryAll1(PageVO pageVO, StudyDataDTO studyDataDTO) {
        IPage<StudyData> page = new Page<>(pageVO.getCurrent(), pageVO.getSize());
        QueryWrapper<StudyData> queryWrapper = new QueryWrapper<>();
        Long id = studyDataDTO.getSafeTypeId();
        if (id != null){
            queryWrapper.eq("safe_type_id",id);
        }
        String keyWords = studyDataDTO.getKeywords();
        if (keyWords != null){
            queryWrapper.eq("keywords",keyWords);
        }
        Integer dataType = studyDataDTO.getDataType();
        if (dataType != null){
            queryWrapper.eq("data_type",dataType);
        }
        Integer isIntroduce = studyDataDTO.getIsIntroduce();
        if (isIntroduce != null){
            queryWrapper.eq("is_introduce",isIntroduce);
        }

        queryWrapper.orderByDesc("create_time");
        return page(page, queryWrapper);
    }

    @Override // 查询所有安全分类名称
    public List<SafeType> selectAllNameSafeType() {
        return safeTypeMapper.selectAllSafeTypeName();
    }

    @Override // 新增学习资料
    public void insertStudyData(StudyData studyData) {
        save(studyData);
    }

    @Override // 更新学习资料
    public void updateStudyData(StudyData studyData) {
        updateById(studyData);
    }

    @Override // 根据id删除学习资料
    public void deleteStudyData(List<Integer> id) {
        removeByIds(id);
    }
}
